//
//  CYDrawCashDetailView.m
//  CaiYun
//
//  Created by 今日信息科技 on 2017/7/13.
//  Copyright © 2017年 今日信息科技. All rights reserved.
//

#import "CYDrawCashDetailView.h"
@interface CYDrawCashDetailView()
@property (nonatomic, strong) CYLabel *balanceLBL; //余额
@property (nonatomic, strong) CYLabel *availableBalanceLBL; //可用余额
@property (nonatomic, strong) CYLabel *bankLBL; //银行
@property (nonatomic, strong) CYLabel *accountLBL; //账号
@property (nonatomic, strong) CYImageView *bankIMG; //银行图标
@property (nonatomic, strong) CYView *topLine;
@property (nonatomic, strong) CYView *bottomLine;

@end
@implementation CYDrawCashDetailView
- (instancetype)initWithColor:(UIColor *)color{
    self = [super initWithColor:color];
    if (self) {
        self.topLine.hidden = self.bottomLine.hidden = self.bankIMG.hidden = NO;
    }
    return self;
}

- (CYLabel *)balanceLBL{
    if (!_balanceLBL) {
        _balanceLBL = [[CYLabel alloc]initWithText:[NSString stringWithFormat:@"余额:%2f元",_balance] size:AL(PT(26)) textcolor:ColorHex(0x888888)];
        [self addSubview:_balanceLBL];
        
        [_balanceLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(AL(PT(27)));
            make.top.equalTo(self).with.offset(AL(PT(75 / 2.0)) - _balanceLBL.bounds.size.height / 2.0);
            make.size.mas_equalTo(_balanceLBL.bounds.size);
        }];
    }
    return _balanceLBL;
}

- (CYLabel *)availableBalanceLBL{
    if (!_availableBalanceLBL) {
        _availableBalanceLBL = [[CYLabel alloc]initWithText:[NSString stringWithFormat:@"可提现余额:%2f元",_availableBalance] size:AL(PT(26)) textcolor:ColorHex(0x888888)];
        [self addSubview:_availableBalanceLBL];
        
        [_availableBalanceLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.mas_right).with.offset(-AL(PT(27)));
            make.top.equalTo(_balanceLBL);
            make.size.mas_equalTo(_availableBalanceLBL.bounds.size);
        }];
    }
    return _availableBalanceLBL;
}
- (CYLabel *)bankLBL{
    if (!_bankLBL) {
        _bankLBL = [[CYLabel alloc]initWithText:_bank size:AL(PT(36)) textcolor:ColorHex(0x333333)];
        [self addSubview:_bankLBL];
        
        [_bankLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_bankIMG.mas_right).with.offset(AL(PT(25)));
            make.top.equalTo(_bankIMG);
            make.size.mas_equalTo(_bankLBL.bounds.size);
        }];
    }
    return _bankLBL;
}
- (CYLabel *)accountLBL{
    if (!_accountLBL) {
        _accountLBL = [[CYLabel alloc]initWithText:_account size:AL(PT(26)) textcolor:ColorHex(0x333333)];
        [self addSubview:_accountLBL];
        
        [_accountLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_bankIMG.mas_right).with.offset(AL(PT(25)));
            make.bottom.equalTo(_bankIMG.mas_bottom);
            make.size.mas_equalTo(_accountLBL.bounds.size);
        }];
    }
    return _accountLBL;
}

- (CYImageView *)bankIMG{
    if (!_bankIMG) {
        _bankIMG = [[CYImageView alloc]initWithImageName:nil size:CGSizeMake(AL(PT(150  - 37 * 2)), AL(PT(150  - 37 * 2))) isRadius:NO];
        _bankIMG.layer.cornerRadius = _bankIMG.bounds.size.width / 2.0;
        _bankIMG.layer.masksToBounds = YES;
        _bankIMG.loadingView.hidden = NO;
        [self addSubview:_bankIMG];
        
        [_bankIMG mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_topLine.mas_bottom).with.offset(AL(PT(37)));
            make.left.equalTo(self).with.offset(AL(PT(25)));
            make.size.mas_equalTo(_bankIMG.bounds.size);
        }];
    }
    return _bankIMG;
}

- (CYView *)topLine{
    if (!_topLine) {
        _topLine = [[CYView alloc]initWithColor:ColorHex(0xf5f5f9)];
        [self addSubview:_topLine];
        
        [_topLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).with.offset(AL(PT(75)));
            make.centerX.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, AL(PT(12))));
        }];
    }
    return _topLine;
}
- (CYView *)bottomLine{
    if (!_bottomLine) {
        _bottomLine = [[CYView alloc]initWithColor:ColorHex(0xf5f5f9)];
        [self addSubview:_bottomLine];
        
        [_bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.mas_bottom).with.offset(0);
            make.centerX.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, AL(PT(12))));
        }];
    }
    return _bottomLine;
}

- (void)setBalance:(float)balance{
    if (_balance != balance)
        _balance = balance;
    self.balanceLBL.text = [NSString stringWithFormat:@"余额:%.2f元",_balance];
}

- (void)setAvailableBalance:(float )availableBalance{
    if (_availableBalance != availableBalance)
        _availableBalance = availableBalance;
    self.availableBalanceLBL.text = [NSString stringWithFormat:@"可提现余额:%.2f元",_availableBalance];
}

- (void)setBank_image:(UIImage *)bank_image{
    if (_bank_image != bank_image)
        _bank_image = bank_image;
    _bankIMG.image = bank_image;
    _bankIMG.loadingView.hidden = YES;
}

- (void)setBank:(NSString *)bank{
    if (_bank != bank)
        _bank = bank;
    self.bankLBL.hidden = NO;
}

- (void)setAccount:(NSString *)account{
    if (_account != account)
        _account = account;
    self.accountLBL.hidden = NO;
}


- (void)updateBalanceLBL{
    
    [_balanceLBL mas_updateConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(_balanceLBL.bounds.size);
    }];
}

- (void)updateAvailableBalance{
    
    [_availableBalanceLBL mas_updateConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(_availableBalanceLBL.bounds.size);
    }];
    
}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
